# coding=utf-8
import os
import time
import unittest
from selenium import webdriver

class BaiduSearch(unittest.TestCase):
    def setUp(self):
        '''
        测试固件的setup()的代码，主要是测试的前提准备工作
        :return:
        '''
        dir = os.path.dirname(os.path.abspath('.'))
        chrome_driver_path = dir + '/tools/chromedriver.exe'
        self.driver = webdriver.Chrome(chrome_driver_path)
        self.driver.implicitly_wait(5)
        self.driver.get('https://www.baidu.com')
    def tearDown(self):
        '''
        测试结束后的操作，这里基本上都是关闭浏览器
        :return:
        '''
        self.driver.quit()
    def test_baidu_search(self):
        '''
        这里一定要test开头，把测试逻辑代码封装在一个test开头的方法里
        :return:
        '''
        self.driver.find_element_by_id('kw').send_keys('selenium')
        time.sleep(2)
        try:
            assert 'selenium' in self.driver.title
            print('test pass')
        except Exception as e:
            print('test fail',format(e))

if __name__ =='__main__':
    unittest.main()



